package com.taoym.voucher.xcx.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.taoym.voucher.xcx.domain.XcxActivity;
import com.taoym.voucher.xcx.entity.vo.XcxGetActivityVO;
import com.taoym.voucher.xcx.mapper.XcxActivityMapper;
import com.taoym.voucher.xcx.service.XcxActivityService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/9/22 15:22
 * @desc
 */
@Service
public class XcxActivityServiceImpl implements XcxActivityService {

    @Resource
    private XcxActivityMapper xcxActivityMapper;

    @Override
    public List<XcxGetActivityVO> listActivities(Integer platform) {

        List<XcxActivity> xcxActivities = xcxActivityMapper.selectList(new QueryWrapper<XcxActivity>()
                .select("act_id", "act_name", "title", "image", "icon","main_act")
                .eq("platform", platform));

        if (CollectionUtils.isEmpty(xcxActivities)) {
            return null;
        }

        return JSON.parseArray(JSON.toJSONString(xcxActivities), XcxGetActivityVO.class);
    }
}
